/**
 * 
 */
package de.cbf.cam.map2d.shapes;

import org.eclipse.swt.graphics.Point;

import de.cbf.cam.map2d.ShapeListenerProvider;
import de.cbf.cam.map2d.interfaces.HoverableShape;
import de.cbf.cam.map2d.interfaces.SelectableShape;
import de.cbf.cam.map2d.listeners.ShapeHoverListener;
import de.cbf.cam.map2d.listeners.ShapeSelectionListener;

/**
 * @author Stefan Alter
 *
 */
public class ShapePlayer extends Sphere implements SelectableShape,HoverableShape {
		
	private Object character;

	private ShapeSelectionListener selectionListener;
	private ShapeHoverListener hoverListener;
	
	/**
	 * @param position
	 */
	public ShapePlayer(Object character,Point position,Integer radius) {
		super(position,radius);
		this.character = character;
		init();
	}
	/**
	 * @param x
	 * @param y
	 */
	public ShapePlayer(Object character,int x, int y,Integer radius) {
		super(x, y,radius);
		this.character = character;	
		init();
	}

	private void init(){
		selectionListener 	= ShapeListenerProvider.getPlayerListener(character);
		hoverListener 		= ShapeListenerProvider.getPlayerListener(character);	
	}
	
	@Override
	public SelectableShape checkCollision(Point toCheck) {
		int a = toCheck.x-middle.x;
		int b = toCheck.y-middle.y;
		double squares =a*a+b*b;
		long c = Math.round(Math.sqrt(squares));
		if(c>radius) return null;
		return this;
	}
	@Override
	public Shape getShape() {
		return this;
	}
	@Override
	public ShapeSelectionListener getSelectionListener() {
		return selectionListener;
	}
	@Override
	public ShapeHoverListener getHoverListener() {
		return hoverListener;
	}	
	
	public void setSelectionListener(ShapeSelectionListener listener) {
		this.selectionListener = listener;
	}
	
	public void setHoverListener(ShapeHoverListener hoverListener) {
		this.hoverListener = hoverListener;
	}
	

}
